<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "gky_group_access".
 *
 * @property string $id
 * @property string $title
 * @property string $pid
 * @property string $sort
 * @property string $url
 * @property integer $hide
 * @property string $tip
 * @property string $group
 * @property integer $is_dev
 * 
 * @property Sub[] $subs
 * @property Parent $parent
 */
class GroupAccess extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'gky_group_access';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['pid', 'sort', 'hide', 'is_dev'], 'integer'],
            [['title', 'group'], 'string', 'max' => 50],
            [['url', 'tip'], 'string', 'max' => 255],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'title' => 'Title',
            'pid' => 'Pid',
            'sort' => 'Sort',
            'url' => 'Url',
            'hide' => 'Hide',
            'tip' => 'Tip',
            'group' => 'Group',
            'is_dev' => 'Is Dev',
        ];
    }
    
     public function getParent(){

        return $this->hasOne(GroupAccess::className(),['id'=>'pid']);
    }

    public function getSubs(){

        return $this->hasMany(GroupAccess::className(),['pid'=>'id'])->orderBy(['sort'=>SORT_ASC]);
    }
    
}
